package com.yayhos.parallaxrecyclerview;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.ListContainer;
import ohos.app.Context;


public class RecyclerView extends ListContainer implements ListContainer.ScrolledListener {

    public RecyclerView(Context context) {
        super(context);
        init();
    }

    public RecyclerView(Context context, AttrSet attrSet) {
        super(context, attrSet);
        init();
    }

    public RecyclerView(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        init();


    }

    private void init() {
        this.setScrolledListener(this);
        this.setLongClickable(false);
    }

    @Override
    public void onContentScrolled(Component component, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
        ListContainer listContainer = (ListContainer) component;
        int size = listContainer.getVisibleIndexCount();
        for (int i = 0; i < size; i++) {
            Component image = listContainer.getComponentAt(listContainer.getItemPosByVisibleIndex(i));
            if(image.getTag() instanceof ParallaxViewHolder){
                ((ParallaxViewHolder) image.getTag()).animateImage();
            }

        }
    }

}
